package cn.com.chengmandian.bike.controller;


import cn.com.chengmandian.agent.utils.AuthUtil;
import cn.com.chengmandian.bike.dto.FaultStationAddForm;
import cn.com.chengmandian.bike.dto.FaultStationDto;
import cn.com.chengmandian.bike.log.ActionLog;
import cn.com.chengmandian.bike.model.EbFaultStation;
import cn.com.chengmandian.bike.model.vo.FaultStationVo;
import cn.com.chengmandian.bike.service.IEbFaultStationService;
import cn.com.chengmandian.core.db.pojo.PageData;
import cn.com.chengmandian.core.web.pojo.AgentInfo;
import cn.com.chengmandian.core.web.pojo.AgentUser;
import cn.com.chengmandian.core.web.pojo.AjaxResult;
import cn.com.chengmandian.core.web.utils.LocalMapUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 电单车运营-申请还车点 前端控制器
 * </p>
 *
 * @author AutoGenerator
 * @since 2021-12-23
 */
@Api(tags = "申请还车点相关接口")
@RestController
@RequestMapping("/fault/station")
public class EbFaultStationController {
    @Autowired
    private IEbFaultStationService faultStationService;

    @ApiOperation("用户申请还车点")
    @PostMapping("/add")
    @ActionLog(name="用户申请还车点",description = "'参数：' + #faultStationAddForm")
    public AjaxResult add(@RequestBody FaultStationAddForm faultStationAddForm) {
        AgentInfo agentInfo = LocalMapUtil.getAgentInfo();
        Assert.notNull(agentInfo.getAreaId(), "缺少运营区ID");
        faultStationAddForm.setAreaId(agentInfo.getAreaId());
        AgentUser agentUser = AuthUtil.getAgentUser();
        faultStationService.addStation(faultStationAddForm, agentUser);
        return AjaxResult.success("提交成功，感谢您的反馈!");
    }

    @ApiOperation("分页")
    @GetMapping("/pages")
    public AjaxResult<PageData<FaultStationVo>> pages(FaultStationDto dto) {
        AgentInfo agentInfo = LocalMapUtil.getAgentInfo();
        Assert.notNull(agentInfo.getAreaId(), "缺少运营区ID");
        dto.setAreaId(agentInfo.getAreaId());
        return AjaxResult.success(PageData.build(faultStationService.getPage(dto, AuthUtil.getAgentUser().getId())));
    }

    @ApiOperation("详情")
    @GetMapping("/detail/{id}")
    public AjaxResult<EbFaultStation> detail(@PathVariable("id") Integer id){
        return AjaxResult.success(faultStationService.getById(id));
    }
}
